package com.itheima.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.service.OrderService_scg;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/order_scg")
public class OrderController_scg {

    @Reference
    private OrderService_scg orderService;

    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){

        try {

            return orderService.findOrderAndMember(queryPageBean);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }


    }

    @RequestMapping("/add")
    public Result add(@RequestBody Map map, int[] ids){

        try {

            return orderService.add(map,ids);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "新增预约失败");
        }

    }

    @RequestMapping("/update")
    public Result update(@RequestBody Map map,int[] ids){


        try {
            orderService.update(map,ids);
            return new Result(true,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"修改失败");
        }

    }
    @RequestMapping("/findById")
    public Result findById(int id){
        try {
            Map map =  orderService.find(id);
            return new Result(true,MessageConstant.QUERY_ORDER_SUCCESS,map);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConstant.QUERY_ORDER_FAIL);
        }
    }

    @RequestMapping("/delete")
    public Result delete(int id){
        try {
            orderService.delete(id);
            return new Result(true,"删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"删除失败");
        }
    }

    @RequestMapping("/updateOrderStatus")
    public Result updateOrderStatus(int id,boolean flag){
        try {
            orderService.updateOrderStatus(id,flag);
            return new Result(true,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true,"修改失败");
        }
    }
}
